<?php

class VoteController extends Controller
{

    public  $step;

    public function init() {
        session_start();
    }


	public function actionIndex()
	{
		$this->render('index');
	}


    public function actionLegislatif($step = 0, $pid = 0)
    {

        $this->step = $step;
        if (isset($_POST['partai'])) {
            $this->redirect(array('legislatif', 'step' => $step, 'pid' => $_POST['partai']));
        }
        elseif ($pid && isset($_POST['caleg'])) {
            $cookieName = 'leg_' . $step;
            $_SESSION[$cookieName] = array($pid, $_POST['caleg']); // "{$pid}-{$_POST['caleg']}";

            if ($step < 3 && (! isset($_SESSION['finished']))) {
                $this->redirect(array('legislatif', 'step' => $step + 1));
            }
            else {
                $_SESSION['finished'] = true;
                $this->redirect(array('finishLegislatif'));
            }
        }

        if (isset($_SESSION['leg_' . $step])) {
            list ($curPartai, $curCaleg) = $_SESSION['leg_' . $step];
        }
        else {
            $curPartai = $curCaleg = -1;
        }

        $this->layout = 'legislatif';
        if ($pid == 0) {
            $this->render('legislatif-partai', array('step' => $step, 'curPartai' => $curPartai));
        }
        else {
            if ($curPartai != $pid) $curCaleg = -1;
            $this->render('legislatif-caleg', array('step' => $step, 'curPartai' => $pid, 'curCaleg' => $curCaleg));
        }
    }

    public function actionFinishLegislatif() {
        if (isset($_POST['submit'])) {
            session_destroy();
            $this->redirect(array('/login/index'));
            return;
        }
        $this->render('finish-legislatif');
    }

    public function actionPresiden() {

        $this->render('presiden');
    }

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}